﻿<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="websocket.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function () {
            //通过POST方法请求，个别浏览器有可能有问题(自行测试)
            // httpposttoserver(1, "Send_content", "");
            //通过Get方法jsonp请求，个别浏览器有可能有问题(自行测试)
            httpgettoserver(1, "Send_content", "");
        });
        var socket;
        function conn()
        {
             socket = new UDCsocket({
                 ip: '127.0.0.1', port: 11001, conn: function () { alert("连接成功"); }
               , recData: function (text) { 
                   $('#test').append("收到:" + text + '<br/>  ')//这个意思你们都懂了把
               }
               , close: function () { alert("连接关闭"); }
                , error: function (msg) { alert("连接错误" + msg); }
                 , jump: function (ip) { alert("服务器超过最大连接，请连接其他服务器："+ip);}
             });
           
        }

        //使用http网关，使用此方法连接。
        function httpposttoserver(command, Request, Root)
        {
            var test = new Object();
            //test.command = 0x2;
            test.Request = Request;//"Send_content";
            if (Root!="")
                test.Root = JSON.stringify(Root);
            else
                test.Root = "";
            test.Parameter ="";
            test.Token = "Token";
            test.Querycount = 0;
            test.Number = '';

            $.ajax({
                type: "post",
                url: "http://127.0.0.1:8080/" + command,
                dataType: "json",
                data: JSON.stringify(test), 
                success: function (data) {
                    alert("success:" + JSON.stringify(data));
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error:" + errorThrown);
                }
            });
        }
        function httpgettoserver(command, Request, Root) {
            var test = new Object();
            //test.command = 0x2;
            test.Request = Request;//"Send_content";
            if (Root != "")
                test.Root = JSON.stringify(Root);
            else
                test.Root = "";
            test.Parameter = "";
            test.Token = "Token";
            test.Querycount = 0;
            test.Number = '';

            $.ajax({
                type: "get",
                url: "http://127.0.0.1:8080/" + command,
                data: JSON.stringify(test),
                dataType: "jsonp",
                jsonp: 'jsoncallback',
                success: function (data) {
                    alert("success:" + JSON.stringify(data));
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error:" + errorThrown);
                }
            });
        }
        function jsoncallback(m )
        {
            alert("success:" + JSON.stringify(m));
        }
        function SendData()
        {
          //  if (socket.takon != "") {
               
                    socket.SendData(0x23, "testaabb", { Str: 'aaaaa' })
           // } else { alert("socket is null"); }
        }
    </script>
</head>
<body>
    <button id='ToggleConnection' type="button" onclick='conn();'>
        连接服务器</button><br />
    <br />
    <button id='ToggleConnection' type="button" onclick='SendData();'>
        发送内容：beston</button><br />
    <br />
    <button id='ToggleConnection' type="button" onclick='seestate();'>
        查看状态</button><br />
    <br />

    <div id="test" style="width:1024px"></div>
</body>
</html>
